package com.net.shop.car.manager.api.volley.response;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.net.shop.car.manager.api.model.Area;
import com.net.shop.car.manager.api.volley.Response;
import com.net.shop.car.manager.utils.Constants;
import com.net.shop.car.manager.utils.LogUtils;

public class HotCityResponse extends Response {

	public HotCityResponse() {
		super(Constants.HOTCITY);
		// TODO Auto-generated constructor stub
	}

	@Override
	public String[] getContentTags() {
		return new String[]{"hotcity","province"};
	}

	private List<Area> hotCity = new ArrayList<Area>();
	
	private List<Area> province = new ArrayList<Area>();

	public List<Area> getHotCity() {
		return hotCity;
	}
	
	@Override
	public void parseContent(String content, int index) {
		if (0 == index) {
			parseHotCity(content);
		} else if (1 == index) {
			parseProvince(content);
		}
	}
	
	/**
	 * @param content String
	 */
	private void parseHotCity(String content) {
		try {
			JSONArray jsonArray = new JSONArray(content);
			int len = jsonArray.length();
			for (int i = 0; i < len; i++) {
				JSONObject jsonObject = jsonArray.getJSONObject(i);
				String id = jsonObject.getString("DIC_NAME");
				String name = jsonObject.getString("DIC_VALUE");
				hotCity.add(new Area(name, id));
			}
		} catch (JSONException e) {
			LogUtils.e(e.getMessage());
		}
	}
	
	/**
	 * @param content
	 */
	private void parseProvince(String content) {
		try {
			JSONArray jsonArray = new JSONArray(content);
			int len = jsonArray.length();
			for (int i = 0; i < len; i++) {
				JSONObject jsonObject = jsonArray.getJSONObject(i);
				String name = jsonObject.getString("NAME");
				String id = jsonObject.getString("ID");
				province.add(new Area(name, id));
			}
		} catch (JSONException e) {
			LogUtils.e(e.getMessage());
		}
	}

	/**
	 * @return the province
	 */
	public List<Area> getProvince() {
		return province;
	}

}
